#
# Package.
#

package iSOCK::Model::Session;

#
# Parent.
#

use Moose;
use namespace::autoclean;

BEGIN { extends 'iSOCK::Model::Root' }

#
# Documentation.
#

=head1 NAME

iSOCK::Model::Session - Catalyst Model

=head1 DESCRIPTION

Catalyst Model.

=head1 AUTHOR

Xavier Caron

=head1 LICENSE

This library is free software. You can redistribute it and/or modify
it under the same terms as Perl itself.

=cut

#
# Functions.
#

sub commit_integration {
  my ( $self, $option ) = @_;
  
  my ( $c, $log ) = ( $option->{c}, $option->{log} );
  
  if ( my $user_r = $c->model ( 'App' )->user_r ( $c ) ) {
    if ( $user_r->assert_user_role ( 'can_commit_specification' ) ) { # FIXME can commit_integration?
      my $session_path = $c->session->{session_path};
      my $parameters   = $c->request->parameters;

      my $milestone    = $parameters->{milestone_shortcut} ? '' : '--' . lc ( $parameters->{milestone_kind} ) . ' ' . $parameters->{milestone_name};

      if ( $parameters->{milestone_shortcut} ne '-' ) {
        $milestone = { 'Next DR stage' => '--next_dr_stage', 'Next DR increment' => '--next_dr_increment' }->{$parameters->{milestone_shortcut}};
      }
      else {
        $milestone = '--' . lc ( $parameters->{milestone_kind} ) . ' ' . $parameters->{milestone_name};
      }

      my $command = 
        "sock_commit_integration $milestone --user " . $user_r->id . " --svn_user " . $c->config->{subversion_user} . " --indent 2 --file_indent 0"
      . ( $parameters->{dummy}   ? ' --dummy'                            : '' )
      . ( $parameters->{message} ? " --message '$parameters->{message}'" : '' )
      ;

      unless ( $self->spawn ( $c, $command, $log ) ) {
        $log->yell ( "Problem during invocation." );
      }
    }
  }
  
  return;
}

#
# True.
#

1;
